<!doctype html>
<html>
	<head>
		<title>我的信息</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="assets/css/amazeui.min.css">
		<link rel="stylesheet" href="assets/css/style.css">
		<link rel="stylesheet" type="text/css" href="assets/css/dcalendar.picker.css"/>
	</head>
	<body>
		<div class="containter" style="height: 100%;">
			<header data-am-widget="header" class="am-header am-header-default">
				<div class="am-header-left am-header-nav">
					<a href="javascript:;" onClick="javascript :history.back(-1);">
						<img src="assets/images/left.png">
					</a>
				</div>
				<h1 class="am-header-title" style="margin:0 14%">
      我的信息
    </h1>
			</header>
			<div style="height: 4rem; width: 100%;"></div>
			<div class="message">
				<form action="">
					<ul>
						<li>
							<img src="assets/images/a14.png"><span>姓名</span><input id="real_name" type="text" maxlength="6" placeholder="请输入您的姓名">
						</li>
						<li>
				          	<img src="assets/images/a10.png"><span>证件类型</span>
				          	<div style="display: inline-block;width:40.8%;position: relative;">
				          		<div id="list_right" id_type="sfz"><b id="id_type">身份证</b></div>
				          		<b style="position: absolute;top:0;right: 0;">▼</b>
				          		<ul id="id_select" style="top:100%;margin: 0;padding: 0;">
							    	<!--<li id="sfz">身份证</li>
							    	<li id="ga">港澳通行证</li>
							    	<li id="passport">护照</li>
							    	<li id="tw">台湾通行证</li>-->
						   	 	</ul>
				          	</div>
				          	
				      	</li>
				      	<li>
				          	<img src="assets/images/a10.png"><span>证件号码</span><input type="text" id="id_number" maxlength="18" />
				      	</li>
				      	<li>
				          <img src="assets/images/a7.png"><span>性别</span>
				          <label class="am-radio M" sex="M">
				            <input id="M" type="radio" name="radio1" value="" data-am-ucheck class="inpt_box"/>
				            男
				          </label>
				          <label class="am-radio F" sex="F" style="margin-right:1rem">
				            <input id="F" class="sex_inpt" type="radio" name="radio1" value="" data-am-ucheck class="inpt_box"/>
				            女
				          </label>
				          <!--<label class="am-radio U" sex="U">
				            <input class="sex_inpt" type="radio" name="radio1" value="" data-am-ucheck class="inpt_box"/>
				            	保密 
				          </label>-->
				      </li>
					</ul>
					<ul>
				      	<li>
							<img src="assets/images/a8.png"><span>出生日期</span><input id="birthday" type="text" onkeydown="return false" style=" height:2.4rem;display: inline-block;" type="text" class="am-form-field" data-am-datepicker placeholder="请输入您的出生日期">
						</li>
						<li>
							<img src="assets/images/a9.png"><span>手机号码</span><input id="phone_num" type="text" readonly="readonly" placeholder="请输入手机号码">
						</li>
				      	
					</ul>
				</form>
				<p><img src="assets/images/a122.png" alt="">身份证、港澳通行证、护照至少必填其中一项</p>
				<button id="change_info">修改资料</button>
			</div>
		</div>
		<div id="toast"></div>
		<script src="assets/js/jquery.min.js"></script>
		<script src="assets/js/allUse.js"></script>
		<script src="assets/js/amazeui.min.js"></script>
		<script src="assets/js/dcalendar.picker.js"></script>
		<!--6.2个人信息修改-->
		<script type="text/javascript">
			//以下 证件列表展开
//					var box=document.getElementsByClassName("box")[0];
//					var p=box.getElementsByTagName("p")[0];
//					var ul=box.getElementsByTagName("ul")[0];
//					var list=ul.getElementsByTagName("li");
					$.ajax({
						type: "get",
						url: url_enter+"/api/get_identity",
						headers: headers,
	                    success: function(data) {
	                    	$('#id_select').append('<li id="sfz">'+data.data.tourist_list[0].ity_name+'</li><li id="ga">'+data.data.tourist_list[1].ity_name+'</li><li id="passport">'+data.data.tourist_list[2].ity_name+'</li><li id="tw">'+data.data.tourist_list[3].ity_name+'</li>')
	                    },
	                    error: function(xhr, status, thrown) {
							console.log(xhr);
						}
                   
        			})
					
					$("#birthday").change(function(){
						$(this).val($(this).attr("value"))
					})
						var listRight=document.getElementById("list_right");
						var idSelect=document.getElementById("id_select");
						var li=idSelect.getElementsByTagName("li");
					listRight.onclick=function(event){
						idSelect.style.display= idSelect.style.display=="block" ? "none" : "block";	
						var evt=event || window.event;
						if(evt.attachEvent){
							evt.cancelBubble=true;	
						}else{
							evt.stopPropagation()	
						}
						for(var i=0;i<li.length;i++){						
							li[i].onclick=function(){
								listRight.innerHTML=this.innerHTML	
								listRight.setAttribute("id_type",this.getAttribute("id"))
							}
						}
					}
					document.onclick=function(){
						idSelect.style.display="none"	
					}
					//输入身份证自动填充出生日期
					if(listRight.getAttribute('id_type')=="sfz"){
						$('#id_number').on('input',function(){
							if($('#id_number').val().length==18){
								var id_num=$('#id_number').val();
								birth=id_num.substring(6, 10) + "-" + id_num.substring(10, 12) + "-" + id_num.substring(12, 14);
								$('#birthday').val(birth);
								if((id_num.substring(16, 17)%2)==0){
									$(".F input[name=radio1]").prop('checked',true);
								}else{
									$(".M input[name=radio1]").prop('checked',true);
								}
							}
						})
					}
					//以上 证件列表展开
			$.ajax({
				type:"get",
				url:url_enter+"/api/get_user_profile",
				headers:headers,
				data:{},
				success:function(data){
					console.log(data);
					
					$("#real_name").val(data.data.real_name);
					if(data.data.gender==""){
						$("#U").attr("checked","checked")
					}else if(data.data.gender=="F"){
						$("#F").attr("checked","checked")
					}else if(data.data.gender=="M"){
						$("#M").attr("checked","checked")
					}else if(data.data.gender=="U"){
						$("#U").attr("checked","checked")
					};
					$("#birthday").val(data.data.birthday);
					$("#phone_num").val(data.data.phone_num);
					switch(data.data.card_type){
						case "ga":
						id_types="ga";
						id_inners="港澳通行证";break;
						case "sfz":
						id_types="sfz";
						id_inners="身份证";
						case "":
						id_types="sfz";
						id_inners="身份证";break;
						case "tw":
						id_types="tw";
						id_inners=" 台湾通行证";break;
						case "passport":
						id_types="passport";
						id_inners="护照";break;
					};
					$("#list_right").attr("id_type",id_types);
					$("#list_right").html(id_inners);
					$("#id_number").val(data.data.card_no);
					$("#change_info").click(function(){
						//var head_img=$(".tou").attr("src");
						var head_img="http://www.ai-peer.com/image/def_avatars.jpg";
						var real_name=$("#real_name").val();
						var gender=$("input[type='radio']:checked").attr("id");
						var birthday=$("#birthday").val();
						var phone_num=$("#phone_num").val();
						var card_type=$("#list_right").attr("id_type");
						var card_no=$("#id_number").val();
						var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
						if(!real_name){
							showToast("请输入姓名");
							return;
						}else if(!phone_num){
							showToast("请输入手机号");
							return;
						}else if(!card_no){
							showToast("请输入证件号号");
							return;
						}else if(!rxPhone.test(phone_num)){
							showToast("手机号码有误");
							return;
						}else if(!birthday){
							showToast("请填写出生日期");
							return;
						}
						var req='{"head_img":"'
						+head_img+'","real_name":"'
						+real_name+'","gender":"'
						+gender+'","birthday":"'
						+birthday+'","phone_num":"'
						+phone_num+'","card_type":"'
						+card_type+'","card_no":"'
						+card_no+'"}';
						console.log(req);
						changeAjax();
						function changeAjax(){
							$.ajax({
								type:"post",
								url:url_enter+"/api/modify_user_profile",
								headers: {
										"User-Token":token,
										"Os":ios_Andriod,
										"Screen": wh,
										"Device-Id":"",
										"Content-Type": "application/x-www-form-urlencoded"
								},
								data:{
									"req":encodeURIComponent(req)
								},
								success:function(data){
									if(data.result===1){
										alert("修改成功");
										window.history.back();
									}else{
										alert(data.message)
									}
								},
								error:function(xhr){
									console.log(xhr)
								}
							})
						}
						
					})
				}
			})
		</script>
	</body>

</html>